package com.ccc.boot.monitor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ccc.boot.entity.SysUserLoginLog;
import com.ccc.boot.monitor.mapper.SysUserLoginLogMapper;
import com.ccc.boot.monitor.service.SysUserLoginLogService;
import com.ccc.boot.pojo.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author superC
 * @version 0.1.0
 * @date 2022/4/10
 */
@Service
public class SysUserLoginLogServiceImpl implements SysUserLoginLogService {

    @Autowired
    private SysUserLoginLogMapper sysUserLoginLogMapper;

    @Override
    public IPage<SysUserLoginLog> pageList(Query query) {
        Page<SysUserLoginLog> page = new Page<>(query.getCurrent(), query.getSize());
        QueryWrapper<SysUserLoginLog> wrapper = new QueryWrapper<>();
        // 全局进行模糊查询
        query.forEach((column, value) -> {
            // 非空，进行模糊查询
            if (value != null && value != "") {
                wrapper.like(column, value);
            }
        });
        wrapper.lambda().orderByDesc(SysUserLoginLog::getCreateTime);
        return sysUserLoginLogMapper.selectPage(page, wrapper);
    }

}
